*****************************************************************************
*SET UP
*****************************************************************************
global root_dir = ""
di "$root_dir"

do "${root_dir}/Code/setup.do"

******************************************************************************************
******************************************************************************************
* PRODUCTIVITY EFFECTS of AI ACCESS
******************************************************************************************
******************************************************************************************

use "$workdir/regfile_agent_month" if agent_active==1, clear

label var rph_cresta "Resolutions/Hr"
label var postXevertreated "Post AI X Ever Treated"
label var ever_treated "Ever Treated"

********************************************************************
* TABLE II - Main DD on Productivity (Resolutions Per Hour)
********************************************************************
reghdfe rph_cresta postXevertreated ever_treated, absorb(chat_ym agent_modecountry agent_modeloc agent_modeteam) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableII.xls", excel replace se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Location FE, Yes, Agent FE, "-", Agent Tenure FE, "-")

reghdfe rph_cresta postXevertreated, absorb(agent_id chat_ym) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableII.xls", excel append se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Location FE, Yes, Agent FE, Yes, Agent Tenure FE, "-")

reghdfe rph_cresta postXevertreated, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableII.xls", excel append se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Location FE, Yes, Agent FE, Yes, Agent Tenure FE, Yes)

******************************************************************************************
*TABLE III - MAIN DD: OTHER OUTCOMES
******************************************************************************************
use "$workdir/regfile_agent_month" if agent_active==1, clear

label var cph "Chats/Hr"
label var tnps_cresta "NPS"
label var fcr_cresta "Res. Rate"
label var aht "AHT"

label var postXevertreated "Post AI X Ever Treated"
label var ever_treated "Ever Treated"


reghdfe aht postXevertreated, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableIII.xls", excel replace se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Agent FE, Yes, Agent Tenure FE, Yes)

reghdfe cph postXevertreated, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableIII.xls", excel append se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Agent FE, Yes, Agent Tenure FE, Yes)

reghdfe fcr_cresta postXevertreated, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableIII.xls", excel append se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Agent FE, Yes, Agent Tenure FE, Yes)

reghdfe tnps_cresta postXevertreated [aweight=survey_count], absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableIII.xls", excel append se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Agent FE, Yes, Agent Tenure FE, Yes)


******************************************************************************************
*C.  EVENT STUDIES -- Abraham and Sun Estimator
* FIGURE II - Event Studies, Productivity
* FIGURE III - Panel A, B, C, D - Event Studies, Additional Outcomes (AHT; CPH; Resolution Rate; Customer Satisfaction (NPS))
* FIGURE X PANEL A - Customer Sentiment, Event Study
* FIGURE X PANEL B - Agent Sentiment, Event Study
* FIGURE X PANEL C - Manager Escalation, Event Study
******************************************************************************************

use "$workdir/regfile_agent_month" if agent_active==1, clear

capture drop ai_cohort
egen ai_cohort = group(ai_ym)
count if ai_cohort==.

capture drop g_*
forvalues k = 10(-1)2 {
	di "`k'"
	gen g_m`k' = rw == -`k'
	label var g_m`k' "-`k'"
}

forvalues k = 0/5 {
	gen g_`k' = rw == `k'
	label var g_`k' "`k'"
}

gen g_m1 = 0
label var g_m1 "-1"

foreach y in $outcomes {

	if "`y'" == "aht" {
	local ytext= "Change in Average Handle Time" 
	local fname = "supplementary_figureIII_panelA"
	}
	else if "`y'" == "cph" {
	local ytext= "Change in Chats Per Hour"
	local fname = "supplementary_figureIII_panelB"
	}
	else if "`y'" == "fcr_cresta" {
	local ytext ="Change in Share Resolved" 
	local fname = "supplementary_figureIII_panelC"
	}
	else if "`y'" == "rph_cresta" {
	local ytext ="Change in Resolutions Per Hour" 
	local fname = "figureII"
	}
	else if "`y'" == "tnps_cresta" {
	local ytext ="Change in Customer Satisfaction (NPS)"  
	local fname = "supplementary_figureIII_panelD"
	}
	else if "`y'" == "askfor_manager" {
	local ytext = "Change in Share Req. Manager"
	local fname = "figureX_panelC"
	}
	else if "`y'" == "agent_sent_mean" {
	local ytext = "Change in Mean(Agent Sentiment)" 
	local fname = "figureX_panelB"
	}
	else if "`y'" == "visitor_sent_mean" {
	local ytext = "Change in Mean(Customer Sentiment)" 
	local fname = "figureX_panelA"
	}

if "`y'" == "tnps_cresta" {
eventstudyinteract `y' g_* [aweight=survey_count], cohort(ai_cohort) control_cohort(never_treated) absorb(agent_id chat_ym agent_tenure_months)  vce(cluster agent_id)	
} 

else {
	eventstudyinteract `y'  g_*, cohort(ai_cohort) control_cohort(never_treated) absorb(agent_id chat_ym agent_tenure_months) vce(cluster agent_id)
}

forvalue i=1(1)15 {
	local m_`i'=e(b_iw)[1,`i']
	local v_`i'=e(V_iw)[`i',`i']
}

matrix input mat1_sa= (`m_1',`m_2',`m_3',`m_4',`m_5',`m_6',`m_7', `m_8',`m_9', 0, `m_10', `m_11', `m_12', `m_13', `m_14', `m_15')
mat colnames mat1_sa= g_m10 g_m9 g_m8 g_m7 g_m6 g_m5 g_m4 g_m3 g_m2 g_m1 g_0 g_1 g_2 g_3 g_4 g_5 

matrix input mat3_sa= (`v_1',`v_2',`v_3',`v_4',`v_5',`v_6',`v_7', `v_8',`v_9', 0, `v_10', `v_11', `v_12', `v_13', `v_14', `v_15')
mat colnames mat3_sa= g_m10 g_m9 g_m8 g_m7 g_m6 g_m5 g_m4 g_m3 g_m2 g_m1 g_0 g_1 g_2 g_3 g_4 g_5 

event_plot mat1_sa#mat3_sa, stub_lag(g_#) stub_lead(g_m#)  ciplottype(rcap) plottype(scatter) ///
		graph_opt($graphbackground xline(-0.5, lpattern(dash) lcolor(gs8)) legend(off) ///
		yline(0, lpattern(solid) lcolor(gs8)) legend(off) ///
		xscale(r(-10.5 5.5)) xtick(-8(1)2) xlabel(-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5, labsize($xlabelsize) nogrid) ///
		ytitle("`ytext'",  size($ytitlesize)) ylabel(, labsize($ylabelsize) nogrid) ///
		xtitle("Months to/from AI Deployment", size($xtitlesize)) ) ///
		lag_opt(msymbol(D) mcolor(midblue) msize(large)) together ///
		lag_ci_opt(lcolor(midblue) lwidth(medium) ) 

graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)
}


******************************************************************************************
************************************************************************************************************************************************************************************
******************************************************************************************
******************************************************************************************
* FIGURE III - Heterogeneity of AI Impact, by Skill at Deployment
* SUPPLEMENTARY FIGURE 12 - Panels C, E
******************************************************************************************
******************************************************************************************

use "$workdir/regfile_agent_month" if agent_active==1, clear

capture drop skill_bin
set seed 1234
egen skill_bin=xtile(lagskillxtile_at_ai), nq(5)

forvalues i=1/5 {
capture drop skilltreat_`i'
gen skilltreat_`i'=(skill_bin==`i')*postXevertreated
}

label var skilltreat_1 "Q1 (Lowest Skilled)"
label var skilltreat_2 "Q2"
label var skilltreat_3 "Q3"
label var skilltreat_4 "Q4"
label var skilltreat_5 "Q5 (Highest Skilled)"

foreach y in $outcomes {

	if "`y'" == "aht" {
	local ytext= "Change in Average Handle Time" 
	local fname="figureIII_panelB"
	}
	else if "`y'" == "cph" {
	local ytext= "Change in Chats Per Hour" 
	local fname="figureIII_panelC"
	}
	else if "`y'" == "fcr_cresta" {
	local ytext ="Change in Share Resolved" 
	local fname="figureIII_panelD"
	}
	else if "`y'" == "rph_cresta" {
	local ytext ="Change in Resolutions Per Hour" 
	local fname="figureIII_panelA"
	}
	else if "`y'" == "tnps_cresta" {
	local ytext ="Change in Customer Satisfaction (NPS)"  
	local fname="figureIII_panelE"
	}
	else if "`y'" == "askfor_manager" {
	local ytext = "Change in Share Req. Manager" 
	local fname="supplementary_figureXVII_panelE"
	}
	else if "`y'" == "visitor_sent_mean" {
	local ytext = "Change in Mean(Customer Sentiment)" 	
	local fname="supplementary_figureXVII_panelC"
	}

if "`y'" == "tnps_cresta" {
reghdfe `y' skilltreat_* [aweight=survey_count], absorb(chat_ym agent_id agent_tenure_months) vce(cluster agent_id)
estadd ysumm 
estimates store `y'_skill_ten
} 

else {
reghdfe `y' skilltreat_*, absorb(chat_ym agent_id agent_tenure_months) vce(cluster agent_id)
estadd ysumm 
estimates store `y'_skill_ten	
}

if "`y'" != "cph" & "`y'" != "visitor_sent_mean" {

coefplot `y'_skill_ten, drop(_cons) vertical base omitted  msymbol(D) mcolor(midblue) msize(large) ciopts(color(midblue) recast(rcap)) /// 
coeflabels(skilltreat_1="Q1 (Lowest)" skilltreat_2="Q2" skilltreat_3="Q3" skilltreat_4="Q4" skilltreat_5="Q5 (Highest)")  /// 
ytitle("`ytext'", size($ytitlesize)) xtitle("Agent Skill at AI Deployment", size($xtitlesize)) xlabel(, ang(45) labsize($xlabelsize) nogrid) yline(0, lcolor(gs8)) $graphbackground  /// 
ylabel(, angle(horizontal) labsize($ylabelsize) nogrid)
graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)
} 
else if "`y'" == "cph" | "`y'" == "visitor_sent_mean" {

coefplot `y'_skill_ten, drop(_cons) vertical base omitted  msymbol(D) mcolor(midblue) msize(large) ciopts(color(midblue) recast(rcap)) /// 
coeflabels(skilltreat_1="Q1 (Lowest)" skilltreat_2="Q2" skilltreat_3="Q3" skilltreat_4="Q4" skilltreat_5="Q5 (Highest)")  /// 
ytitle("`ytext'", size($ytitlesize)) xtitle("Agent Skill at AI Deployment", size($xtitlesize)) xlabel(, ang(45) labsize($xlabelsize) nogrid)  $graphbackground  /// 
ylabel(, angle(horizontal) labsize($ylabelsize) nogrid)
graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)

} 
else  {
	di as err "Uncaught case"
}

}

******************************************************************************************
* FIGURE IV - Heterogeneity of AI Impact, by Tenure at Deployment
* SUPPLEMENTARY FIGURE 12 - Panels D, F
******************************************************************************************
use "$workdir/regfile_agent_month" if agent_active==1, clear

capture drop tenure_bin
gen tenure_bin=.
replace tenure_bin=1 if tenure_at_ai_months==0 
replace tenure_bin=2 if tenure_at_ai_months>=1 & tenure_at_ai_months<=2 
replace tenure_bin=3 if tenure_at_ai_months>=3 & tenure_at_ai_months<=6 
replace tenure_bin=4 if tenure_at_ai_months>=7 & tenure_at_ai_months<=12 
replace tenure_bin=5 if tenure_at_ai_months>12 

forvalues i=1/5 {
capture drop tenuretreat_`i'
gen tenuretreat_`i'=(tenure_bin==`i')*postXevertreated
}

label var tenuretreat_1 "<1 Mos."
label var tenuretreat_2 "1-2 Mos."
label var tenuretreat_3 "3-6 Mos."
label var tenuretreat_4 "7-12 Mos."
label var tenuretreat_5 ">12 Mos."

foreach y in $outcomes {
	if "`y'" == "aht" {
	local ytext= "Change in Average Handle Time" 
	local fname="figureIV_panelB"
	}
	else if "`y'" == "cph" {
	local ytext= "Change in Chats Per Hour" 
	local fname="figureIV_panelC"
	}
	else if "`y'" == "fcr_cresta" {
	local ytext ="Change in Share Resolved" 
	local fname="figureIV_panelD"
	}
	else if "`y'" == "rph_cresta" {
	local ytext ="Change in Resolutions Per Hour" 
	local fname="figureIV_panelA"
	}
	else if "`y'" == "tnps_cresta" {
	local ytext ="Change in Customer Satisfaction (NPS)"  
	local fname="figureIV_panelE"
	}
	else if "`y'" == "askfor_manager" {
	local ytext = "Change in Share Req. Manager" 
	local fname="supplementary_figureXVII_panelD"
	}
	else if "`y'" == "visitor_sent_mean" {
	local ytext = "Change in Mean(Customer Sentiment)" 	
	local fname="supplementary_figureXVII_panelF"
	}

if "`y'" == "tnps_cresta" {
       reghdfe `y' tenuretreat_* [aweight=survey_count], absorb(chat_ym agent_id i.lagskillxtile_at_ai ) vce(cluster agent_id)
    estadd ysumm
	estimates store `y'_ten_sk
} 

else {
    reghdfe `y' tenuretreat_*, absorb(chat_ym agent_id i.lagskillxtile_at_ai ) vce(cluster agent_id)
    estadd ysumm
    estimates store `y'_ten_sk
}

if "`y'" != "visitor_sent_mean" {
    coefplot `y'_ten_sk, drop(_cons) vertical base omitted  msymbol(D) mcolor(midblue) msize(large) ciopts(color(midblue) recast(rcap)) coeflabels(tenuretreat_1="0 Mos." tenuretreat_2="1-2 Mos." tenuretreat_3="3-6 Mos." tenuretreat_4="7-12 Mos." tenuretreat_5=">12 Mos.") ytitle("`ytext'", size($ytitlesize)) xtitle("Agent Tenure at AI Deployment", size($xtitlesize)) xlabel(, ang(45) labsize($xlabelsize) nogrid) yline(0, lcolor(gs8)) $graphbackground  ylabel(, angle(horizontal) labsize($ylabelsize) nogrid)
    graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)
} 
else if  "`y'" == "visitor_sent_mean" {
    coefplot `y'_ten_sk, drop(_cons) vertical base omitted  msymbol(D) mcolor(midblue) msize(large) ciopts(color(midblue) recast(rcap)) coeflabels(tenuretreat_1="0 Mos." tenuretreat_2="1-2 Mos." tenuretreat_3="3-6 Mos." tenuretreat_4="7-12 Mos." tenuretreat_5=">12 Mos.") ytitle("`ytext'", size($ytitlesize)) xtitle("Agent Tenure at AI Deployment", size($xtitlesize)) xlabel(, ang(45) labsize($xlabelsize) nogrid)  $graphbackground  ylabel(, angle(horizontal) labsize($ylabelsize) nogrid)
    graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)
} 
else  {
	di as err "Uncaught case"
}


}



******************************************************************************************
*LEARNING CURVE BEFORE AND AFTER AI
* FIGURE 5 - Experience Curves by Deployment Cohort for RPH
******************************************************************************************

use "$workdir/regfile_agent_month" if agent_active==1 , clear

gen sample=.
replace sample=1 if ever_treated==0
replace sample=2 if ever_treated==1 & tenure_at_ai_months==0
replace sample=3 if ever_treated==1 & (tenure_at_ai_months==5|tenure_at_ai_months==6)

replace agent_tenure_months=5 if agent_tenure_months>5 & agent_tenure_months!=. & sample==2
replace agent_tenure_months=10 if agent_tenure_months>10 & agent_tenure_months!=. & sample==3

foreach y in $mainoutcomes {
	if "`y'" == "aht" {
	local ytext= "Average Handle Time" 
	local fname = "supplementary_figureVI_panelA"
	}
	else if "`y'" == "cph" {
	local ytext= "Chats Per Hour" 
	local fname = "supplementary_figureVI_panelB"
	}
	else if "`y'" == "fcr_cresta" {
	local ytext ="Share Resolved" 
	local fname = "supplementary_figureVI_panelC"
	}
	else if "`y'" == "rph_cresta" {
	local ytext ="Resolutions Per Hour" 
	local fname = "figureV"
	}
	else if "`y'" == "tnps_cresta" {
	local ytext ="Customer Satisfaction (NPS)" 
	local fname = "supplementary_figureVI_panelD"
	}

if "`y'" == "tnps_cresta" {
    binsreg `y' agent_tenure_months if agent_tenure_months<=10 [aweight=survey_count], by(sample) dots(0,0) line(3,3) ci(3,3) cb(3,3) bycolors(blue red green) bysymbols(o T S) bylpatterns(longdash_dot  dash solid) polyreg(4) xtitle("Agent Tenure, Months") ytitle("`ytext'") legend(order(1 "Never Treated" 4 "Always Treated" 7 "Treated 5-6 Mo.")) scale(.9)  bgcolor(white) plotregion(color(white)) graphregion(color(white))
    graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)
}

else {
    binsreg `y' agent_tenure_months if agent_tenure_months<=10 [aweight=nchats], by(sample) dots(0,0) ///
 line(3,3) ci(3,3) cb(3,3) bycolors(blue red green) bysymbols(o T S) bylpatterns(longdash_dot  dash solid) polyreg(4) xtitle("Agent Tenure, Months", size($xtitlesize))  /// 
 ytitle("`ytext'",  size($ytitlesize)) legend(order(1 "Never Treated" 4 "Always Treated" 7 "Treated 5-6 Mo.")) scale(.9)  $graphbackground ///
 xline(6, lpattern(dash) lcolor(gs8)) yline(2.5, lpattern(dash) lcolor(black)) ylabel(, labsize($ylabelsize)) xlabel(,labsize($xlabelsize)) savedata(${figures_dir}/learningcurvedata_`y') replace
    graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)
}
}

******************************************************************************************
******************************************************************************************
*HETEROGENEITY BY TOPIC
*See topics_analysis.do
************************************************************************************************************************************************************************************
******************************************************************************************

******************************************************************************************
*ADHERANCE
************************************************************************************************************************************************************************************
******************************************************************************************
*A.  DISTRIUTION OF ADHERENCE
* FIGURE VI PANEL A - Heterogeneity of AI Impact, by AI Adherence - Distribution of AI Adherence
******************************************************************************************

use "$workdir/regfile_agent_month" if agent_active==1, clear
replace receptivity=. if months_since_treat<0
gen lntot_shints=log(tot_shints)

sum receptivity [aweight=lntot_shints], d
kdensity receptivity [aweight=lntot_shints], xtitle("AI Percent Adherance") title("")  color(blue%40) recast(area) bgcolor(white) plotregion(color(white)) graphregion(color(white))  ylabel( , nogrid) xlabel( , nogrid)
graph export "${figures_dir}/figureVI_panelA.pdf", replace


******************************************************************************************
*B.  HETEROGENEITY IN RETURNS BY RECEPTIVITY
* FIGURE VI PANEL B - Heterogeneity of AI Impact, by AI Adherence -  Impact of AI on Resolutions Per Hour, by Initial Adherence
******************************************************************************************
use "$workdir/regfile_agent_month" if agent_active==1, clear

capture drop recept_bin
set seed 1234
egen recept_bin=xtile(receptivity_atai1), nq(5)

forvalues i=1/5 {
gen recepttreat_`i'=(recept_bin==`i')*postXevertreated
tab recepttreat_`i', missing
}

foreach y in $mainoutcomes {
	if "`y'" == "aht" {
	local ytext= "Change in Average Handle Time" 
	local fname = "supplementary_figureX_panelA"
	}
	else if "`y'" == "cph" {
	local ytext= "Change in Chats Per Hour" 
	local fname = "supplementary_figureX_panelB"
	}
	else if "`y'" == "fcr_cresta" {
	local ytext ="Change in Share Resolved" 
	local fname = "supplementary_figureX_panelC"
	}
	else if "`y'" == "rph_cresta" {
	local ytext ="Change in Resolutions Per Hour" 
	local fname = "figureVI_panelB"
	}
	else if "`y'" == "tnps_cresta" {
	local ytext ="Change in Customer Satisfaction (NPS)" 
	local fname = "supplementary_figureX_panelD"
	}

if "`y'" != "tnps_cresta" {
    reghdfe `y' recepttreat_*, absorb(chat_ym agent_id agent_tenure_months)
    estadd ysumm
    estimates store `y'_recept

    coefplot `y'_recept, drop(_cons) vertical base omitted xline(6, lcolor("navy"))  msymbol(D) mcolor(midblue) msize(large) ciopts(color(midblue) recast(rcap)) coeflabels(recepttreat_1="Q1 (Low)" recepttreat_2="Q2" recepttreat_3="Q3" recepttreat_4="Q4" recepttreat_5="Q5 (High)")  ytitle("`ytext'", size($ytitlesize)) xtitle("Initial Adherence at AI Deployment (%)" , size($xtitlesize)) xlabel(, ang(45) labsize($xlabelsize) nogrid) ylabel(, angle(horizontal) labsize($ylabelsize) nogrid)  $graphbackground
    graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)

}
else if "`y'" == "tnps_cresta"{
	reghdfe `y' recepttreat_* [aweight=survey_count], absorb(chat_ym agent_id agent_tenure_months)
    estimates store `y'_recept

    coefplot `y'_recept, drop(_cons) vertical base omitted xline(6, lcolor("navy"))  msymbol(D) mcolor(midblue) msize(large) ciopts(color(midblue) recast(rcap)) coeflabels(recepttreat_1="Q1 (Low)" recepttreat_2="Q2" recepttreat_3="Q3" recepttreat_4="Q4" recepttreat_5="Q5 (High)")  ytitle("`ytext'", size($ytitlesize)) xtitle("Initial Adherence at AI Deployment (%)" , size($xtitlesize)) xlabel(, ang(45) labsize($xlabelsize) nogrid) ylabel(, angle(horizontal) labsize($ylabelsize) nogrid)  $graphbackground
    graph export "${figures_dir}/`fname'.eps", as(eps) preview(on) replace  fontface($graphfont)
}
else  {
	di as err "Uncaught case"
}
}



******************************************************************************************
*EXPERIENCE OF WORK
************************************************************************************************************************************************************************************



******************************************************************************************
* TABLE IV: IMPACT OF AI ON AGENT AND CUSTOMER SENTIMENT AND MANAGER ESCALATION
******************************************************************************************

use "$workdir/regfile_agent_month" if agent_active==1, clear

label var visitor_sent_mean "Mean(Customer Sentiment)"
label var agent_sent_mean "Mean(Agent Sentiment)"
label var askfor_manager "Share Req. Manager"

label var postXevertreated "Post AI X Ever Treated"
label var ever_treated "Ever Treated"

sum visitor_sent_mean 
reghdfe visitor_sent_mean postXevertreated, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableIV.xls", excel  replace se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Agent FE, Yes, Agent Tenure FE, Yes)

sum agent_sent_mean
reghdfe agent_sent_mean postXevertreated, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableIV.xls", excel  append se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Agent FE, Yes, Agent Tenure FE, Yes)

sum askfor_manager
reghdfe askfor_manager postXevertreated, absorb(agent_id chat_ym agent_tenure_months) cluster(agent_id)
estadd ysumm 
outreg2 * using "${tables_dir}/tableIV.xls", excel  append se label auto(3) nocons alpha(0.01, 0.05, 0.10) tex(frag) addstat(DV Mean, e(ymean)) addtext(Year Month FE, Yes, Agent FE, Yes, Agent Tenure FE, Yes)

